package bishi.alibaba;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
//合并石柱，相邻相同合并
//每次1、减去最矮的非0，2、合并相邻的。
//输出次数和每次的结果
//30%
//4
//        4 3 2 1
/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/07/20 19:22
 */
public class one2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new LinkedList<>();
        sc.nextLine();
        int min = Integer.MAX_VALUE;
        while (n > 0) {
            n--;
            int now = sc.nextInt();
            if (list.size() > 0 && list.get(list.size() - 1) == now) {
                continue;
            }
            min = now != 0 ? Math.min(min, now) : min;
            list.add(now);
        }
        int res = 0;
        List<Integer> list1 = new ArrayList<>();
        while (list.size() > 1) {
            res++;
            int jian = min;
            min = Integer.MAX_VALUE;
            for (int i = 0; i < list.size(); i++) {
                int now = list.get(i);
                now = now >= jian ? now - jian : now;
                if (i > 0 && list.get(i - 1) == now) {
                    list.remove(i);
                    i--;
                } else {
                    list.set(i, now);
                    min = now != 0 ? Math.min(min, now) : min;
                }
            }
            list1.add(list.size());
        }
        System.out.println(res);
        for (int i = 0; i < list1.size(); i++) {
            System.out.print(list1.get(i) + " ");
        }
    }
}
